/**
 * Created by Administrator on 15-10-8.
 */
window.onload=function(){
    var id = $.getUrlParam("id");
    var url=getUrl();
    var userid=getUserId();
    var pager = 1;
    $.jsonp({
        url: 'http://'+url+'/api/collect/collect_sameway_list',
        data: {userId:userid,pager:pager},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            //console.log(data);
            $.each(data.arrays,function(index,ele){

                var day=new Date(ele.endTime*1000)-new Date(ele.startTime*1000);
                //var day= parseInt(Math.abs((ele.endTime - ele.startTime))/(1000*60*60*24))+1;
                var day= parseInt(day/(1000*60*60*24))+1;
                var unixTimestamp = new Date(ele.startTime*1000)
                commontime = unixTimestamp.toLocaleString();
                var unixTimestamp = new Date(ele.endTime*1000)
                commonTime = unixTimestamp.toLocaleString();
                var id =ele.id;
                var sex=ele.sex;
                var sexstr='icons-sex-female';
                var sexbgstr='sex sex-female';
                if(sex==1){
                    sexstr="icons-sex-male";
                    sexbgstr='sex sex-male';
                }
                var jumpurl = "jumptoLogin("+"'wode_tongyou_shoucangny.html?id="+ele.samewayId+"','wode_tongyou_shoucangny.html?id="+ele.samewayId+"')";
                var html = '<div onclick="'+jumpurl+'">' +
                    '<div class="ui-source-pic">' +
                    '<img src="'+ele.photos[0]+'" height="300" class="round-pic" alt="">' +
                    '<i class="icons-flag">'+day+'日游</i>' +
                    '<div class="ui-source-pic-detail">' +
                    '<div class="ui-source-pic-avatar">' +
                    '<img src="'+ele.photo+'" width="35" height="35" alt="">' +
                    '</div>' +
                    '<div class="ui-source-pic-content">' +
                    '<div class="clearfix">' +
                    '<div class="ui-source-pic-name">' +
                    ''+ele.nickName+'<span class="' + sexbgstr + '"><i class="' + sexstr + '"></i>'+ele.age+'</span>' +
                    '</div>' +
                    '<div class="ui-source-pic-number">' +
                    ''+ele.enterIds+'人已报名' +
                    '</div>' +
                    '</div>' +
                    '<div class="ui-source-pic-date">' +
                    ''+getTime(ele.startTime)+' / <a>'+day+'</a>天 '+ele.goAddress+','+ele.toAddress+'' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</div>' +
                    '</a>';
                $("#wdtycc").append(html);
                if(data.arrays.length<15){
                    $(".load-more").text("");
                    return;
                }
            })
        },
        error: function (xOptions, textStatus) {

        }
    });
    $(".load-more").on("click",function() {
        pager = pager + 1;
        $.jsonp({
            url: 'http://'+url+'/api/collect/collect_sameway_list',
            data: {userId:userid,pager:pager},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {
                //console.log(data);
                $.each(data.arrays,function(index,ele){

                    var day=new Date(ele.endTime*1000)-new Date(ele.startTime*1000);
                    //var day= parseInt(Math.abs((ele.endTime - ele.startTime))/(1000*60*60*24))+1;
                    var day= parseInt(day/(1000*60*60*24))+1;
                    var unixTimestamp = new Date(ele.startTime*1000)
                    commontime = unixTimestamp.toLocaleString();
                    var unixTimestamp = new Date(ele.endTime*1000)
                    commonTime = unixTimestamp.toLocaleString();
                    var id =ele.id;
                    var sex=ele.sex;
                    var sexstr='icons-sex-female';
                    var sexbgstr='sex sex-female';
                    if(sex==1){
                        sexstr="icons-sex-male";
                        sexbgstr='sex sex-male';
                    }
                    var jumpurl = "jumptoLogin("+"'wode_tongyou_shoucangny.html?id="+ele.samewayId+"','wode_tongyou_shoucangny.html?id="+ele.samewayId+"')";
                    var html = '<div onclick="'+jumpurl+'">' +
                        '<div class="ui-source-pic">' +
                        '<img src="'+ele.photos[0]+'" height="300" class="round-pic" alt="">' +
                        '<i class="icons-flag">'+day+'日游</i>' +
                        '<div class="ui-source-pic-detail">' +
                        '<div class="ui-source-pic-avatar">' +
                        '<img src="'+ele.photo+'" width="35" height="35" alt="">' +
                        '</div>' +
                        '<div class="ui-source-pic-content">' +
                        '<div class="clearfix">' +
                        '<div class="ui-source-pic-name">' +
                        ''+ele.nickName+'<span class="' + sexbgstr + '"><i class="' + sexstr + '"></i>'+ele.age+'</span>' +
                        '</div>' +
                        '<div class="ui-source-pic-number">' +
                        ''+ele.enterIds+'人已报名' +
                        '</div>' +
                        '</div>' +
                        '<div class="ui-source-pic-date">' +
                        ''+getTime(ele.startTime)+' / <a>'+day+'</a>天 '+ele.goAddress+','+ele.toAddress+'' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '</a>';
                    $("#wdtycc").append(html);
                    if(data.arrays.length<15){
                        $(".load-more").text("");
                        return;
                    }
                })
            },
            error: function (xOptions, textStatus) {

            }
        });
    });
    //alert($.getUrlParam("id"));
}
//function onBackKeyDown() {
//    jumpbyback(0,"");
//}
function getTime(t){
    var nt = t*1000;
    var n = new Date(nt);
    return formatDate(n);
}
function formatDate(now)   {
    var   year=now.getFullYear();
    var   month=now.getMonth()+1;
    var   date=now.getDate();
    return   year+"-"+(month>=10?month:"0"+month)+"-"+(date>=10?date:"0"+date);
}